package com.colorlight.cloud.complete.entity.event;

import com.colorlight.cloud.complete.api.CompleteEntityEvent;
import com.colorlight.iot.proto.complete.event.CompleteEvent;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * 设备主体参数上报
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class GetMainDeviceInfo implements CompleteEntityEvent {

    /**
     * 设备主体型号
     */
    private String mainModel;

    @Override
    public GetMainDeviceInfo byteConvertObject(ByteString bytes) {
        CompleteEvent.GetMainDeviceInfo getMainDeviceInfo = null;
        try {
            getMainDeviceInfo = CompleteEvent.GetMainDeviceInfo.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            log.error("", e);
        }
        Objects.requireNonNull(getMainDeviceInfo);
        this.setMainModel(getMainDeviceInfo.getMainModel());
        return this;
    }
}

